package designpattern.observer;

import java.util.Observable;
import java.util.Observer;

import designpattern.observer.Heater;

/**
 * 显示器
 * @author liuboen
 * 
 * since:2012-6-7
 * version:1.0.0
 */
public class Display extends Observable implements Observer {

	private String status = "NORMAL";
	 
    public String getStatus() {
       return status;
    }
 
    public void setStatus(String status) {
       this.status = status;
    }
 
    @Override
    public void update(Observable o, Object arg) {
       this.displayTemperature(((Heater) o).getTemperature());
    }
 
    private void displayTemperature(int temperature) {
       if (temperature > 100) {
           this.setStatus("ABNORMAL");
           this.setChanged();
           this.notifyObservers(temperature);
       }
       System.out.println("当前温度状态:" + status + "  温度为 " + temperature +"℃");
    }

}
